package com.ydgk.jishuzhan.dao;

import com.ydgk.jishuzhan.beans.Blog;
import com.ydgk.jishuzhan.beans.BlogCollection;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface BlogMapper {
    List<Blog> findBlogs();

    int save(Blog blog);

    @Select("select * from blog where id = #{id}")
    Blog findBlog(Integer id);

    @Select("select * from blog where userId= #{id}")
    List<Blog> findBlogsByUserId(Integer id);

    @Select("select count(*) from blog_good where blogId=#{id}")
    int findGoods(Integer id);

    @Insert("insert into blog_good (userId,blogId) values (#{userId},#{blogId})")
    void goodAdd(@Param("userId") Integer userId, @Param("blogId") Integer blogId);

    @Select("select count(*) from blog_good where userId=#{userId} and blogId=#{blogId}")
    int findGood(@Param("userId") Integer userId, @Param("blogId") Integer blogId);

    @Select("select count(*) from collection_blog where userId=#{userId} and blogId=#{blogId}")
    int finCollection(Integer userId, Integer blogId);

    @Insert("insert into collection_blog (userId,blogId) values (#{userId},#{blogId})")
    void collectAdd(Integer userId, Integer blogId);

    @Select("select count(*) from collection_blog where blogId=#{id}")
    int findCollections(Integer id);

    List<BlogCollection> getCollections(Map<String, Object> map);

    Integer queryBlogTotal(Map<String, Object> map);

    @Delete("delete from collection_blog where id =#{id}")
    void deleteBCollection(Integer id);
}
